<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>合美供销云平台登录</title>
	<!-- 样 式 文 件 -->
	<link rel="stylesheet" href="component/pear/css/pear.css" />
	<link rel="stylesheet" href="elementUI/index.css">
	<link rel="stylesheet" href="admin/css/other/login.css" />
	<style>
		[v-cloak] {
			display: none;
		}
	</style>
</head>
<!-- 代 码 结 构 -->

<body style="background-size: cover;">
	<div id="app">
		<div class="container">
			<form class="layui-form" action="javascript:void(0);">
				<div class="layui-form-item">
					<div class="logo"></div>
					<div style="text-align: center;font-size: 0.9rem;">
						<h1><span>合美供销云平台</span></h1>
					</div>
					<div class="text">欢迎登录</div>
					<!-- <div class="desc">
							明 湖 区 最 具 影 响 力 的 设 计 规 范 之 一
						</div> -->
				</div>
				<el-tabs type="border-card">
					<el-tab-pane label="手机号">
						<div class="layui-form-item">
							<input placeholder="请输入您注册时填写的手机号" v-model="formData.username" class="layui-input" />
							<span style="color: red;" v-cloak>{{usertishi}}</span>
						</div>
						<div class="layui-form-item" id="password">
							<input :type="passwordShow ? 'text' : 'password'" placeholder="请输入您注册时填写的密码"
								v-model="formData.password" class="layui-input" />
							<span style="color: red;" v-cloak>{{passtishi}}</span>
							<div @click="passwordShow = !passwordShow">
								<img v-if="passwordShow" src="./admin/images/eye.png" alt="">
								<img v-else src="./admin/images/eyes.png" alt="">
							</div>
						</div>
						<div class="layui-form-item">
							<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
							<el-button @click="window.location.href = 'register.html'" class="register-button"
								type="text">立即注册</el-button>
						</div>
						<div class="layui-form-item">
							<el-button class="my-button" type="primary" @click="handleLogin">登 录</el-button>
						</div>
					</el-tab-pane>
					<el-tab-pane label="验证码登录">
						<div style="margin: 20px;"></div>
						<el-form :label-position="labelPosition" label-width="60px" :model="formLabelAlign">
							<el-form-item label="手机号">
								<el-input v-model="formLabelAlign.name"></el-input>
							</el-form-item>
							<el-form-item label="验证码">
								<el-input v-model="formLabelAlign.region">
									<el-button slot="append" @click="sendMessage()"
										icon="el-icon-position">{{time?'发送':secend+'秒'}}</el-button>
								</el-input>
								<div style="margin-right:10%;margin-top: 10px;">
									<el-button class="my-button" @click="handleLogin1" type="primary" >登 录</el-button>
								</div>
						</el-form>
					</el-tab-pane>
				</el-tabs>
			</form>

		</div>
	</div>
	<!-- 资 源 引 入 -->
	<script src="component/layui/layui.js"></script>
	<script src="component/pear/pear.js"></script>
	<script type="text/javascript" src="js/jquery-3.6.0.min.js"></script>
	<script type="text/javascript" src="./js/jquery.cookie.js"></script>
	<script type="text/javascript" src="js/vue.min.js"></script>
	<script type="text/javascript" src="elementUI/index.js"></script>
	<script type="text/javascript" src="js/utils.js"></script>
	<script>
		new Vue({
			el: '#app',
			data() {
				return {
					labelPosition: 'right',
					loading: false,
					passwordShow: false,
					usertishi: '',
					passtishi: '',
					formData: {
						username: '',
						password: '',
						url: 'index.html',
					},
					formLabelAlign: {
						username: '',
						phone:true,
						region: ''
					},
					time: true,
					secend: 60,
					timer: null
				}
			},
			methods: {
				sendMessage() {
					if (this.time && !this.formData.username == '') {
						this.time = false
						this.secend = 60
						this.secend--
						this.timer = setInterval(() => {
							if (this.secend == '01') {
								clearInterval(this.timer)
								this.time = true
								return
							}
							this.secend--
							if (this.secend < 10) {
								this.secend = '0' + this.secend
							}
						}, 1000)
						let code = '';
						for (let i = 0; i < 6; i++) {
							code += parseInt(Math.random() * 10);
						}
						console.log(this.formData.username);
						$.ajax({
							type: 'GET',
							url: `https://marketingservice.ediblefungus.cn/send/verification/${this.formLabelAlign.name}/6/5`,
							success: (res)=> {
								console.log(res);
								if(res){
									this.$message({
										type: 'success',
										message: '发放成功！'
									});
								}else{
									this.$message({
										type: 'errer',
										message: '系统错误!请稍后重试'
									});
								}
							},
							dataType: "json"
						});
					}
					// username
				},
				handleLogin1() {
					if (!this.loading) {
						let _this = this;
						this.usertishi = '';
						this.passtishi = '';
						if (this.formLabelAlign.username == '') {
							this.usertishi = '手机号不能为空';
						} else if (this.formLabelAlign.region == '') {
							// this.passtishi = '密码不能为空';
						} else {
							this.loading = true
							$.ajax({
								url: DomainName + '/OpenURLAction',
								type: 'POST',
								data: _this.formData,
								complete: function (XMLHttpRequest) {
									_this.loading = false
									console.log(XMLHttpRequest)
									if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
										$.cookie('token', XMLHttpRequest.getResponseHeader("Cookies"))
										$.cookie('use', XMLHttpRequest.getResponseHeader("USE"))
										$.cookie('enterprise', XMLHttpRequest.getResponseHeader("ENTERPRISE"))
										$.cookie('enterpriseName', XMLHttpRequest.getResponseHeader("ENTERPRISENAME"))
										console.log(XMLHttpRequest.getResponseHeader("ENTERPRISENAME"));
										if (XMLHttpRequest.getResponseHeader("Resuit") == 'ERROR') {
											_this.$notify.error({
												title: '错误',
												message: '账号或者密码错误'
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'RIGHTS') {
											_this.$notify.warning({
												title: '未认证',
												message: '该账号未认证,无法登陆!'
											});
											_this.$confirm('该账号未认证,无法登陆, 是否前往认证?', '提示', {
												confirmButtonText: '确定',
												cancelButtonText: '取消',
												type: 'warning'
											}).then(() => {
												window.document.location.href = 'https://marketing.ediblefungus.cn/dist/h5XKLJ/index.html#/pages/authentication/authentication'
											}).catch(() => {
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'EXAMINE') {
											_this.$notify.warning({
												title: '企业审核中',
												message: '该账号代审核中,暂时无法登陆!'
											});

										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'REFUSE') {
											_this.$notify.warning({
												title: '未通过',
												message: '该账号审核未通过,请重新注册!'
											});
										} else {
											window.parent.document.location.href = XMLHttpRequest.getResponseHeader("Contentpath");
											// window.parent.document.location.href = './rotate.html';
											window.history.go(-1)
										}

									}
								},
								success: function (result) {
									console.log(result);
									// if (result.Status == "success") {
									// 	window.location.href = 'index.html';
									// } else {
									// 	_this.$notify.error({
									// 		title: '提示',
									// 		message: '用户名或密码错误！'
									// 	});
									// }
								},
								error: function (params) {
									console.log(params);
								}
							})
						}

					}
				},
				handleLogin() {
					if (!this.loading) {
						let _this = this;
						this.usertishi = '';
						this.passtishi = '';
						if (this.formData.username == '') {
							this.usertishi = '用户名不能为空';
						} else if (this.formData.password == '') {
							this.passtishi = '密码不能为空';
						} else {
							this.loading = true
							$.ajax({
								url: DomainName + '/OpenURLAction',
								type: 'POST',
								data: _this.formData,
								complete: function (XMLHttpRequest) {
									_this.loading = false
									console.log(XMLHttpRequest)
									if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
										$.cookie('token', XMLHttpRequest.getResponseHeader("Cookies"))
										$.cookie('use', XMLHttpRequest.getResponseHeader("USE"))
										$.cookie('enterprise', XMLHttpRequest.getResponseHeader("ENTERPRISE"))
										$.cookie('enterpriseName', XMLHttpRequest.getResponseHeader("ENTERPRISENAME"))
										console.log(decodeURI($.cookie('enterpriseName')));
										if (XMLHttpRequest.getResponseHeader("Resuit") == 'ERROR') {
											_this.$notify.error({
												title: '错误',
												message: '账号或者密码错误'
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'RIGHTS') {
											_this.$notify.warning({
												title: '未认证',
												message: '该账号未认证,无法登陆!'
											});
											_this.$confirm('该账号未认证,无法登陆, 是否前往认证?', '提示', {
												confirmButtonText: '确定',
												cancelButtonText: '取消',
												type: 'warning'
											}).then(() => {
												window.document.location.href = 'https://marketing.ediblefungus.cn/dist/h5XKLJ/index.html#/pages/authentication/authentication'
											}).catch(() => {
											});
										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'EXAMINE') {
											_this.$notify.warning({
												title: '企业审核中',
												message: '该账号代审核中,暂时无法登陆!'
											});

										} else if (XMLHttpRequest.getResponseHeader("Resuit") == 'REFUSE') {
											_this.$notify.warning({
												title: '未通过',
												message: '该账号审核未通过,请重新注册!'
											});
										} else {
											window.parent.document.location.href = XMLHttpRequest.getResponseHeader("Contentpath");
											// window.parent.document.location.href = './rotate.html';
											// window.history.go(-1)
										}

									}
								},
								success: function (result) {
									console.log(result);
									// if (result.Status == "success") {
									// 	window.location.href = 'index.html';
									// } else {
									// 	_this.$notify.error({
									// 		title: '提示',
									// 		message: '用户名或密码错误！'
									// 	});
									// }
								},
								error: function (params) {
									console.log(params);
								}
							})
						}

					}
				},
				changeView() {
					this.passwordShow = !this.passwordShow
				}
			}
		})
	</script>
</body>

</html>